package org.pockito.dctmpersistence.mock;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

import com.documentum.fc.common.IDfTime;

public class DfTime implements IDfTime {

	public static final String DATE_PATTERN = "dd/MM/yyyy HH:mm:ss";

	public static final DateFormat dateFormat = new SimpleDateFormat(DATE_PATTERN, Locale.US);
	
	private Date theDate;
	
	public DfTime() {
		super();
		this.theDate = new Date(0);
	}

	public DfTime(Date aDate) {
		super();
		this.theDate = aDate;
	}

	public DfTime(String aDate) {
		try {
			this.theDate = dateFormat.parse(aDate);
		} catch (ParseException ignore) {
			this.theDate = null;
		}
	}

	public String asString(String arg0) {
		return dateFormat.format(theDate);
	}

	public int compareTo(IDfTime arg0) {
		return theDate.compareTo(arg0.getDate());
	}

	public Date getDate() {
		return theDate;
	}

	@SuppressWarnings("deprecation")
	public int getDay() {
		return theDate.getDay();
	}

	@SuppressWarnings("deprecation")
	public int getHour() {
		return theDate.getHours();
	}

	@SuppressWarnings("deprecation")
	public int getMinutes() {
		return theDate.getMinutes();
	}

	@SuppressWarnings("deprecation")
	public int getMonth() {
		return theDate.getMonth();
	}

	public String getPattern() {
		return DATE_PATTERN;
	}

	@SuppressWarnings("deprecation")
	public int getSeconds() {
		return theDate.getSeconds();
	}

	@SuppressWarnings("deprecation")
	public int getYear() {
		return theDate.getYear();
	}

	public boolean isNullDate() {
		return theDate == null || (theDate.equals(new Date(0L)));
	}

	public boolean isValid() {
		return theDate != null;
	}

	public static String format(Date aDate) {
		// TODO Auto-generated method stub
		return dateFormat.format(aDate);
	}

}
